package com.lanyan.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;
        import com.lanyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.mapper.WithdrawMapper;
import com.lanyan.system.domain.Withdraw;
import com.lanyan.system.domain.vo.WithdrawVo;
import com.lanyan.system.service.IWithdrawService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 提现Service业务层处理
 *
 * @author lanyan
 * @date 2024-11-26
 */
@Service
public class WithdrawServiceImpl  extends ServiceImpl<WithdrawMapper,Withdraw> implements IWithdrawService

{
    @Autowired
    private WithdrawMapper withdrawMapper;

    /**
     * 查询提现
     *
     * @param withdrawId 提现主键
     * @return 提现
     */
    @Override
    public Withdraw selectWithdrawByWithdrawId(Long withdrawId)
    {
        return this.getById(withdrawId);
    }

    /**
     * 查询提现Vo列表
     *
     * @param withdraw 提现
     * @return 提现
     */
    @Override
    public List<WithdrawVo> selectWithdrawVoList(Withdraw withdraw)
    {
        return selectWithdrawList(withdraw)
                .stream()
                .map(x -> (WithdrawVo)x)
                .collect(Collectors.toList());
    }
    /**
     * 查询提现列表
     *
     * @param withdraw 提现
     * @return 提现
     */
    @Override
    public List<Withdraw> selectWithdrawList(Withdraw withdraw)
    {
        LambdaQueryChainWrapper<Withdraw> wrapper = this.lambdaQuery().eq(Withdraw::getDelFlag,"0");
        if (withdraw.getAccountId() != null) {
            wrapper.eq(Withdraw::getAccountId, withdraw.getAccountId());
        }
        if (withdraw.getMoney() != null) {
            wrapper.eq(Withdraw::getMoney, withdraw.getMoney());
        }
        if (StringUtils.isNotEmpty(withdraw.getSate())) {
            wrapper.eq(Withdraw::getSate, withdraw.getSate());
        }
        if (StringUtils.isNotEmpty(withdraw.getCause())) {
            wrapper.eq(Withdraw::getCause, withdraw.getCause());
        }
        return wrapper.list();
    }

        /**
         * 新增提现
         *
         * @param withdraw 提现
         * @return 结果
         */
    @Override
        public boolean insertWithdraw(Withdraw withdraw)
        {
                    withdraw.setCreateTime(DateUtils.getNowDate());
                return this.save(withdraw);
        }

        /**
         * 修改提现
         *
         * @param withdraw 提现
         * @return 结果
         */
    @Override
        public boolean updateWithdraw(Withdraw withdraw)
        {
                    withdraw.setUpdateTime(DateUtils.getNowDate());
            return this.updateById(withdraw);
        }

        /**
         * 批量删除提现
         *
         * @param withdrawIds 需要删除的提现主键
         * @return 结果
         */
    @Override
        public boolean deleteWithdrawByWithdrawIds(Long[] withdrawIds)
        {
            return this.lambdaUpdate().set(Withdraw::getDelFlag,"1").in(Withdraw::getWithdrawId,withdrawIds).update();
        }

        /**
         * 删除提现信息
         *
         * @param withdrawId 提现主键
         * @return 结果
         */
    @Override
        public boolean deleteWithdrawByWithdrawId(Long withdrawId)
        {
            return this.lambdaUpdate().set(Withdraw::getDelFlag,"1").eq(Withdraw::getWithdrawId,withdrawId).update();
        }
    }
